<template>
  <!-- 新增药物 -->
  <div id="chufang">
    <span @click="backto()" class="flowL">{{ back }}后退</span>
    <br />
    <br />
    <Chufangheader :patientInfo="patientInfo" @age="age" @sex="sex"></Chufangheader>
    <div v-for="(d, index) in counter" class="getchufangall" :key="index">
      <Addchufang></Addchufang>
    </div>
    <el-button type="success" @click="Addchufang()" round>添加药物</el-button>
    <el-button type="success" @click="getall()" round>成功按钮</el-button>
    <Peintchufang :chuafangdata="chufangdata" :patientInfo="patientInfo" />
  </div>
</template>

<script>
import { mapActions, mapMutations, mapGetters } from 'vuex';
import Addchufang from '@/components/addchufang';
import Chufangheader from '@/components/chufangheader';
import Peintchufang from '@/components/printchufang';

export default {
  data() {
    return {
      back: '<',
      counter: [{}],
      chufang: {},
      chufangdata: '',
      patientInfo: '',
    };
  },
  components: {
    Addchufang,
    Chufangheader,
    Peintchufang,
  },

  created() {
    // this.patientInfo = this.$route.params
    this.patientInfo = this.$route.query;
  },

  methods: {
    ...mapActions(['tongyong']),
    backto() {
      this.$router.go(-1);
    },
    sex(v) {
      this.patientInfo.sex = v;
      // this.patientInfo=JSON.stringify(JSON.parse(this.patientInfo))
    },
    age(v) {
      this.patientInfo.age = v;
    },
    // 新增药物
    Addchufang() {
      this.counter.push({});
    },
    get() {
      this['tongyong']({
        name: 'GET_ALLDOCTOR',
        data: {},
      }).then(response => {
        console.log(response);
      });
    },
    // 整合数据
    getall() {
      let arr = [];
      let count = 0;

      if (!$('.doctorid>.el-input>input')[0].value) {
        this.$message({
          message: '提交前请检查你的医生id',
          type: 'warning',
        });
      } else {
        this.chufang.doctorid = $('.doctorid>.el-input>input')[0].value;
        this.chufang.chufangnum = $('.chufangnum')[0].innerHTML;
        this.chufang.SubjectName = $('.SubjectName')[0].innerHTML;
        for (let i = 0; i < $('.getchufangall ').length; i++) {
          if (!$('.everoneid>input')[i].value || !$('.everoneneed>input')[i].value) {
            this.$message({
              message: '提交前请确定你的处方单是否有空白',
              type: 'warning',
            });
          } else {
            (count = count * 1 + $('.everonecount')[i].innerHTML * 1),
              arr.push({
                danwei: $('.danwei')[i].innerHTML,
                mediNo: $('.everoneid>input')[i].value,
                quantity: $('.everoneneed>input')[i].value,
                mediName: $('.everonename')[i].innerHTML,
                mediMoney: $('.everonecount')[i].innerHTML,
                unit: $('.danjia')[i].innerHTML,
              });
            this.chufang.chufanlist = arr;
            this.chufang.count = count;
          }
        }
        //  for(let item in this.patientInfo) {
        //       console.log(item);
        //       console.log(this.patientInfo[item]);
        //   }
        this.patientInfo = JSON.parse(JSON.stringify(this.patientInfo));
        this.chufangdata = JSON.parse(JSON.stringify(this.chufang));
        console.log(this.chufangdata);
        $('#hidden').show();
        // console.log(this.chufang);
      }
    },
  },
};
</script>

<style scoped></style>
